﻿using AutoMapper;
using J.Model;
using J.ProductSet.Application.Command.ReleaseAppointmentCommand;
using MediatR;
using SqlSugar;

namespace J.ProductSet.Application.CommandHandler.ReleaseAppointmentCommandHandler
{
    public class ReleaseAppointmentPostCommandHandler : IRequestHandler<ReleaseAppointmentPostCommand, int>
    {
        private readonly ISqlSugarClient _sqlSugarClient;
        public IMapper _mapper;
        public ReleaseAppointmentPostCommandHandler(ISqlSugarClient sqlSugarClient, IMapper mapper)
        {
            _sqlSugarClient = sqlSugarClient;
            _mapper = mapper;
        }
        public Task<int> Handle(ReleaseAppointmentPostCommand request, CancellationToken cancellationToken)
        {
            ReleaseAppointment release = _mapper.Map<ReleaseAppointment>(request);
            return  _sqlSugarClient.Insertable(release).ExecuteCommandAsync();
        }
    }
}
